﻿using A.M.Storage.Application;
using A.M.Storage.I_Infrastruecure;
using O.M.Production.Application.IService;
using O.M.Production.Domain.Entity;
using O.M.Production.ErrorCodeEnum;
using O.M.Production.Infrastuecure.IRepository;
using System;
using System.Collections.Generic;
using System.Data.Entity.Validation;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace O.M.Production.Application.Service
{
    /// <summary>
    /// 工序管理服务接口实现类
    /// </summary>
    public class working_procedure_manage_Service : BaseServices<working_procedure_manage, string>, I_working_procedure_manage_Service
    {
        private readonly I_working_procedure_manage_Repository _working_Procedure_Manage_Repository;
        public working_procedure_manage_Service(I_working_procedure_manage_Repository working_Procedure_Manage_Repository) : base(working_Procedure_Manage_Repository)
        {
            _working_Procedure_Manage_Repository = working_Procedure_Manage_Repository;
        }
        /// <summary>
        /// 分页查询-工序管理
        /// </summary>
        /// <param name="WId_WName">工序id或工序名称</param>
        /// <param name="pageSize">页容量</param>
        /// <param name="pageIndex">页码</param>
        /// <returns>统一返回格式</returns>
        public async Task<ApiResult> Get_working_procedure_manage(string? WId_WName, int pageSize, int pageIndex)
        {
            try
            {
                ApiResult apiResult=new ApiResult();
                Expression<Func<working_procedure_manage, bool> > whereidname = i => true;
                if (!string.IsNullOrEmpty(WId_WName))
                {
                    whereidname = i => i.working_procedure_id.Contains(WId_WName) || i.working_procedure_name.Contains(WId_WName);
                }
                var list=await _working_Procedure_Manage_Repository.GetShowQueryableAsync(pageSize, pageIndex,whereidname);
                apiResult.Data = list.Data.OrderByDescending(x => x.working_procedure_id);
                apiResult.totalCount = list.TotalCount;
                apiResult.pageCount = list.PageCount;
                return apiResult;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw;
            }
        }
    }
}
